<template>
  <div>
    <!-- 绘制form的静态页 -->
    <!-- 4.使用info -->
    <el-dialog title="会员编辑" :visible.sync="info.isshow" @closed="close">
      <el-form :model="form">
        {{ form }}
        <el-form-item label="手机号" label-width="120px">
          <el-input v-model="form.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="昵称" label-width="120px">
          <el-input v-model="form.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" label-width="120px">
          <el-input v-model="form.password" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="状态" label-width="120px">
          <el-switch
            v-model="form.status"
            :active-value="1"
            :inactive-value="2"
          ></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="quxiao">取 消</el-button>
        <el-button type="primary" @click="xiugai">修 改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { reqmemberinfo, reqmemberedit } from "../../../request/api";
import { successAlert } from "../../../utils/alert";
export default {
  // 3.收info
  props: ["info"],
  data() {
    return {
      //表单数据
      form: {
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      },
    };
  },
  computed: {},
  mounted() {},
  methods: {
    ...mapActions({
      //获取分类list
      reqList: "vip/reqList",
      //总数
      reqTotal: "vip/reqTotal",
    }),
    //7.取消
    quxiao() {
      this.info.isshow = false;
    },
    // 清空
    qingkong() {
      this.form = {
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      };
    },
    //获取一条数据
    getOne(id) {
      //取数据
      reqmemberinfo({ uid: id }).then((res) => {
        if (res.data.code == 200) {
          this.form = res.data.list;
          this.form.password = "";
        }
      });
    },
    //修改
    xiugai() {
      // 2.将form发送给后端修改
      //修改请求
      reqmemberedit(this.form).then((res) => {
        //修改成功
        if (res.data.code == 200) {
          // 1.弹成功
          successAlert(res.data.msg);
          // 2.表单清空
          this.qingkong();
          // 3.弹框消失
          this.info.isshow = false;
          // 4.列表更新
          this.reqList();
        }
      });
    },
    //弹框关闭
    close() {
      // 是编辑，要清空表单
      !this.info.isAdd && this.qingkong();
    },
  },
};
</script>
<style scoped lang="less">
@import "../../../less/index.less";
.box {
  display: flex;
}
.el-input {
  flex: 1;
}
</style>